package com.amado.course49AnonymousClass.zuoye;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.amado.course27.entity.Goods;
import com.amado.course49AnonymousClass.Student;

public class ComparetorTest<T> {
	static List<Student> studentList = new ArrayList();

	public static void main(String[] args) {
		ComparetorTest<Student> test = new ComparetorTest();
		test.add(new Student("张三", 60));
		test.add(new Student("李四", 20));
		test.add(new Student("张三", 41));
		test.add(new Student("王五", 11));
		test.add(new Student("王五", 91));
		/**
		 * a negative integer, zero, or a positive integer as the
		 * first argument is less than, equal to, or greater than the
		 * second.
		 *
		 * o1与o2比较 于小返咽负数，==返回0，大于返回正数
		 */
		studentList.sort(new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return o2.getAge()-o1.getAge();
			}
		});
		test.print();
		
	}

	public void add(Student t) {
		studentList.add(t);
	}


	public void print() {
		for (Student t:studentList) {
			System.out.println(t);
		}
	}
}
